package cn.zzm.mybatisplus.controller;

import cn.zzm.mybatisplus.dto.User;
import cn.zzm.mybatisplus.dto.UserDto;
import cn.zzm.mybatisplus.service.impl.UserServiceImpl;
import com.rt.entity.vo.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO().
 *
 * <p>TODO().
 *
 * <p>版权所有:Copyright (c) 2019<br/>
 * <a href="http://www.wiseimage.cn/">广州易联众睿图信息技术有限公司</a>.
 *
 * @author 周昭名
 * @version V1.0
 * @since 2019/6/10 18:51
 */
@RestController
@Slf4j
public class UserController {
    @Autowired
    UserServiceImpl userService;

    @RequestMapping("list")
    public List<User> getUserList(){
        UserDto dto = new UserDto();
        dto.setName("zzm");
        dto.setStartCreateTime("2019-01-01 20:00:00");
        return userService.getList(dto);
    }

    @RequestMapping("listPage")
    public JsonResult getUserListPage(){
        UserDto dto = new UserDto();
        dto.setPageNo(1);
        dto.setPageSize(3);
        dto.setName("zzm");
        return userService.getListPage(dto);
    }

    @RequestMapping("listAll")
    public List<User> getUserListAlll(){
        return userService.getList(null);
    }

    @RequestMapping("update")
    public String updateUser(){
        User user = new User();
        user.setId(6L);
        user.setName("zzm1");
        user.setEmail("zzm@163.com");
        userService.updateByPrimaryKeySelective(user);
        return "更新成功！";
    }

    @RequestMapping("insert")
    public String insertUser(){
        User user = new User();
        //user.setId(6L);
        user.setName("zzm");
        user.setAge(30);
        user.setEmail("test6@baomidou.com");
        userService.insertSelective(user);
        return "新增成功！";
    }


}
